
/*
 * Copyright (c) 2013.
 * 游戏服务器核心代码编写人陈磊拥有使用权
 * 联系方式：E-mail:13638363871@163.com ;qq:502959937
 * 个人博客主页：http://my.oschina.net/chenleijava
 */

package com.dc.gameserver.serverCore.controller.handleController;

import com.dc.gameserver.proto.gameserverprotoVo.outPKRequest;
import com.dc.gameserver.proto.gameserverprotoVo.outPKResponse;
import com.dc.gameserver.serverCore.controller.AbstractController.AbstractController;
import com.dc.gameserver.serverCore.controller.AbstractController.IController;
import com.dc.gameserver.serverCore.service.character.PlayerInstance;
import com.dc.gameserver.serverCore.service.cardModule.CardBox;
import com.dc.gameserver.serverCore.service.cardModule.CardBoxManager;
import com.google.protobuf.MessageLite;
import org.springframework.stereotype.Service;

/**
 * @author : 石头哥哥
 *         Project : LandlordsServer
 *         Date: 13-6-4
 *         Time: 上午11:49
 *         Connect: 13638363871@163.com
 *         packageName: Server.ServerCore.Controller
 *         离开pk状态：
 *         1.回收cardBox对象所持有的资源；
 */
@Service
public class outPkController extends AbstractController {

    /**
     */
    @Override
    public void PostConstruct() {
        int ID= outPKRequest.msgID.ID_VALUE;
       GAME_CONTROLLERS[ID]=this;   //业务逻辑处理引用
       IController.MESSAGE_LITE[ID]= outPKRequest.getDefaultInstance();   //解析的pb实体类型
    }
     /**
     * messageLite数据结构体分发
     *
     * @param messageLite
     * @param player
     * @throws Exception
     */
    @Override
    public void DispatchMessageLit(MessageLite messageLite, PlayerInstance player) throws Exception {
        //玩家离开pk状态  messageLite==null
        //清理pk状态中所占用的资源
        CardBox cardBox=CardBoxManager.getCardBoxByID(player.getCardBoxID());
        outPKResponse.Builder builder= outPKResponse.newBuilder();
        builder.setPlayerID(player.getID());
        cardBox.submitMessageToEveryOne(wrappedBufferShort(outPKResponse.msgID.ID_VALUE, builder.build()));
        CardBoxManager.clearPkResourceWithRoundOver(cardBox.getCardBoxID());
    }
}
